package com.android.fragmentdemo.adapters
import android.util.Log
import androidx.databinding.ViewDataBinding
import com.hengfoxwolf.commonbase.base.databeans.TurnTableItem
import com.android.fragmentdemo.databinding.LayoutEmptyViewBinding
import com.android.fragmentdemo.databinding.RvTurnTableItemLayoutBinding
import com.hengfoxwolf.commonbase.base.adapter.BaseRvAdapter3

class TurnTableAdapter2 : BaseRvAdapter3<TurnTableItem, RvTurnTableItemLayoutBinding,LayoutEmptyViewBinding>(RvTurnTableItemLayoutBinding::inflate,LayoutEmptyViewBinding::inflate) {

    override fun bindData(holder: ViewHolder, dataItem: TurnTableItem, position: Int) {
        if (holder.binding is RvTurnTableItemLayoutBinding) {
            (holder.binding as RvTurnTableItemLayoutBinding).tvContentTurnTable.apply {
                text = dataItem.content
                setBackgroundColor(context.resources.getColor(dataItem.color))
            }
        }
        Log.d("TurnTableAdapter2", "position:${position}")
    }

    override fun listenerWithBinding(binding: ViewDataBinding) {
        super.listenerWithBinding(binding)
        Log.d("TurnTableAdapter2", "tag:${binding.root.id}")
        if (binding is RvTurnTableItemLayoutBinding) {
            binding.tvContentTurnTable.setOnClickListener {
                mOnItemClickListener?.onItemClick(binding.root.tag as TurnTableItem, binding.root.id, binding.root.id)
            }
        }
    }
}